dhcpv4: lazy store statefiles
Currently, the dhcpv4 server saves the statefile on every change and
also calls the leasetrigger script every time the statefile is updated
(which triggers a dnsmasq reload).
In addition, odhcpd wakes up every second (see dhcpv4_valid_until_cb())
to go through all existing leases to see if any lease has expired.
With this change, the wakeups are reduced to every 5 seconds, and the
statefile is only written (if necessary) during that wakeup.
Before this change (without any leasetrigger, test on my laptop, not a
real OpenWrt device):
$ time sudo ./build/dhcpdig -4 benchmark foo-client
Thread[**]: req
10000101/0 rel
10000101/0 rep
10000101/0
real 55m29.406s
user 0m0.005s
sys 0m0.010s
(This is a simple benchmark tool I wrote, it runs 10 threads which
divide the DHVPv4 pool into 10 chunks and then performs 1 million random
addr req/release per thread in a loop).
After this change:
$ time sudo ./build/dhcpdig -4 benchmark foo-client
Thread[**]: req
10000101/0 rel
10000101/0 rep
10000101/0
real 1m48.123s
user 0m0.005s
sys 0m0.005s
A 3082% speedup.
Signed-off-by: David Härdeman <[email protected]>
Link: https://github.com/openwrt/odhcpd/pull/298
Signed-off-by: Álvaro Fernández Rojas <[email protected]>